﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Serialization;
namespace CoreModule
{
    /// <summary>
    /// 默认 功能配置
    /// </summary>
    public class FunctionConfigurationInfo
    {
        public FunctionConfigurationInfo() { }
        static string XmlFilePath = "FunctionConfigurationInfo.xml";

        /// <summary>
        /// 
        /// </summary>
        public static FunctionConfigurationInfo Load()
        {
            if (File.Exists(XmlFilePath))
            {
                try
                {
                    using (FileStream fileStream = new FileStream(XmlFilePath, FileMode.OpenOrCreate))
                    {
                        var conf = (FunctionConfigurationInfo)new XmlSerializer(typeof(FunctionConfigurationInfo)).Deserialize(fileStream);
                        return conf;
                    }
                }
                catch (Exception)
                {
                    File.Delete(XmlFilePath);
                    return new FunctionConfigurationInfo();
                }
            }
            return new FunctionConfigurationInfo();

        }

     
        /// <summary>
        /// /
        /// </summary>
        public void Save()
        {
            if (File.Exists(XmlFilePath))
            {
                File.Delete(XmlFilePath);
            }
            try
            {
                using (FileStream fileStream = new FileStream(XmlFilePath, FileMode.OpenOrCreate))
                {
                    new XmlSerializer(typeof(FunctionConfigurationInfo)).Serialize(fileStream, this);
                }
            }
            catch (Exception)
            {
            }
        }
        [XmlIgnore()]
        public List<KeyValuePair<string, int>> MeasurementTimeItems { get; set; } = new List<KeyValuePair<string, int>> {
                    new KeyValuePair < string, int >("90s",90),
                    new KeyValuePair < string, int >("120s",120),
                    new KeyValuePair < string, int >("150s",150),
    };
        [XmlIgnore()]
        public List<KeyValuePair<string, int>> DisplayTimeItems { get; set; } = new List<KeyValuePair<string, int>> {
                new KeyValuePair < string, int >("5s",5),
                new KeyValuePair < string, int >("10s",10),
                new KeyValuePair < string, int >("15s",15),
                new KeyValuePair < string, int >("20s",20),
    };
        /// <summary>
        /// 测量等待时间（秒）
        /// </summary>
        public int MeasurementTimeout { get; set; } = 120;
        /// <summary>
        /// 显示默认时间（秒）
        /// </summary>
        public int DisplayTimeout { get; set; } = 15;
        /// <summary>
        /// 没有使用。
        /// </summary>
        public bool EnableKeyboard { get; set; } = true;
        /// <summary>
        /// 启用管理端
        /// </summary>
        public bool EnableManagement { get; set; } = true;
        /// <summary>
        /// 匿名测量
        /// </summary>
        public bool AnonymousMeasurement { get; set; } = true;
        /// <summary>
        /// 匿名存储,没有使用。
        /// </summary>
        public bool AnonymousStore { get; set; } = true;
        /// <summary>
        /// 匿名上传,没有使用。
        /// </summary>
        public bool AnonymousUpload { get; set; } = true;
    }
}
